<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class ProfitShareOrder extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {
        $this->table('profit_share_order', ['comment' => '分润订单表'])
            ->addColumn('out_separate_no', 'string', ['length' => 32,'comment' => '商户分账指令流水号'])
            ->addColumn('merchant_no', 'string', ['length' => 32,'comment' => '商户号'])
            ->addColumn('user_id', 'integer', ['signed' => false,'comment' => '用户id'])
            ->addColumn('total_amt', 'integer', ['signed' => false,'comment' => '订单金额(分)'])
            ->addColumn('lkl_org_no', 'string', ['length' => 16,'comment' => '拉卡拉机构编号'])
            ->addColumn('cal_type', 'integer', ['signed' => false,'comment' => '分账计算类型 0- 按照指定金额，1- 按照指定比例。默认 0'])
            ->addColumn('recv_merchant_no', 'string', ['length' => 32,'comment' => '接收方商户号'])
            ->addColumn('recv_no', 'string', ['length' => 32,'comment' => '分账接收方编号'])
            ->addColumn('separate_value', 'decimal', ['precision' => 10, 'scale' => 2,'comment' => '分账数值 calType为0时，按照固定金额分账，单位：分 calType为1时，按照比例分账，单位：百分比的小数值，比如0.55 （55%）'])
            ->addColumn('separate_no', 'string', ['length' => 32,'comment' => '分账指令流水号'])
            ->addColumn('status', 'enum', ['values' => ['PENDING','PROCESSING', 'ACCEPTED', 'SUCCESS', 'FAIL'], 'comment' => '分账状态 待处理: PENDING 处理中：PROCESSING, 已受理：ACCEPTED, 成功：SUCCESS, 失败：FAIL'])
            ->addColumn('fee_amt', 'integer', ['signed' => false,'comment' => '分账手续费(分)'])
            ->addColumn('fail_reason', 'string', ['length' => 256,'comment' => '分账失败原因'])
            ->addColumn('cmd_type', 'enum', ['values' => ['SEPARATE', 'CANCEL', 'FALLBACK'], 'comment' => '指令类型'])
            ->addTimestamps('create_time', 'update_time')
            ->addIndex(['out_separate_no'], ['unique' => true])
            ->create();
    }
}
